package pers.jphoebe.quartz.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.jphoebe.quartz.api.juhe.GoldApi;
import pers.jphoebe.quartz.entity.GoldPrice;
import pers.jphoebe.quartz.entity.SilverPrice;
import pers.jphoebe.quartz.entity.Variety;
import pers.jphoebe.quartz.entity.juhe.GoldData;
import pers.jphoebe.quartz.entity.juhe.JuheResponse;
import pers.jphoebe.quartz.entity.response.ResponseData;
import pers.jphoebe.quartz.exception.CustomException;
import pers.jphoebe.quartz.service.GoldDataFromJuheService;
import pers.jphoebe.quartz.service.VarietyService;
import pers.jphoebe.quartz.utils.IdUtil;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;

/**
 * Created by 蒋时华 on 2017/10/31.
 */
@RestController
public class TestController {

    @Autowired
    private GoldApi goldApi;
    @Autowired
    private VarietyService varietyService;
    @Autowired
    private GoldDataFromJuheService goldDataFromJuheService;

    @GetMapping("/testGold")
    public GoldPrice testGold(){
        GoldPrice latestGoldTDPrice = goldDataFromJuheService.getLatestGoldTDPrice();
        return latestGoldTDPrice;
    }
    @GetMapping("/testSilver")
    public SilverPrice testSilver(){
        return goldDataFromJuheService.getLatestSilvetyTDPrice();
    }
    @GetMapping("/testJuhe")
    public Object testJuhe(){
        try{
            goldDataFromJuheService.saveJuheGoldDataByVariety();
        }catch (CustomException e){
            return "fails";
        }
        return "success";
    }

    @GetMapping("/init")
    public String init(){
        Variety variety = new Variety();
        variety.setId(IdUtil.getId());
        variety.setName("Au(T+D)");
        variety.setStatus(1);
        variety.setTypeCode(1);
        varietyService.saveVariety(variety);

        variety = new Variety();
        variety.setId(IdUtil.getId());
        variety.setName("Ag(T+D)");
        variety.setStatus(1);
        variety.setTypeCode(2);
        varietyService.saveVariety(variety);
        return "success";
    }

}
